class Solution {
    
public:
    string minWindow(string s, string t) {
        unordered_map<char, int> need;
        unordered_map<char, int> window;
        for(char a:t)
        {
            ++need[a];
        }

        int start=0,l=0,count=0;
        int length=INT_MAX;
        for(int i=0;i<s.size();i++)
        {
            if(need.count(s[i]))
            {
                ++window[s[i]];
                if(window[s[i]]==need[s[i]]) ++count;
            }

            while(count==need.size())
            {
                if(i-l+1<length)
                {
                    start=l;
                    length=i-l+1;
                }
                if(need.count(s[l]))
                {
                    --window[s[l]];
                    if(window[s[l]]<need[s[l]]) --count;
                }
                ++l;
            }

        }

        return length==INT_MAX?"":s.substr(start,length);
    }
};